package edu.algo3.algoThief.dao;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jdom2.Element;

public class DatosPaises extends repositorioXML {

	// ********* Variables de instancia **********
	
	private static String nombreDocumentoXML = "datos/pistas/xml/datosPaises.xml";
	
	// ********* Constructores **********
	
	protected DatosPaises()
	{
		
	}
	
	// ********* Getters **********
	
	protected static ArrayList<String> getListaDePaises()
	{
		parseDocumento(nombreDocumentoXML);
		return obtieneTodosLosPaises();
	}
	
	protected static ArrayList<String> getDatosSobrePais(String pais)
	{
		parseDocumento(nombreDocumentoXML);
		return obtieneDatosPais(pais);
	}
	
	// ********* Setters **********
	
	// ********* Metodos de instancia **********
	
	private static ArrayList<String> obtieneTodosLosPaises()
	{
		ArrayList<String> listaDePaises = new ArrayList<String>();

		List<Element> paises = racine.getChildren("pais");
		Iterator<Element> i1 = paises.iterator();
		while(i1.hasNext())
		{
			Element pais = (Element)i1.next();
			listaDePaises.add((pais.getAttribute("paisNombre")).getValue());
		}
		
		return listaDePaises;
	}
	
	private static ArrayList<String> obtieneDatosPais(String paisNombre)
	{
		ArrayList<String> datosPais = new ArrayList<String>();

		List<Element> paises = racine.getChildren("pais");
		Iterator<Element> i1 = paises.iterator();
		while(i1.hasNext())
		{
			Element pais = (Element)i1.next();
			if ((pais.getAttribute("paisNombre")).getValue().equals(paisNombre))
			{
				List<Element> caracteristicas = pais.getChildren();
				Iterator<Element> i2 = caracteristicas.iterator();
				while(i2.hasNext())
				{
					Element caracteristica = (Element)i2.next();
					datosPais.add(caracteristica.getText()); 
				}
			}
		}
		
		return datosPais;
	}
	
}
